package cn.kgm.makeGodV2.ruleEngine;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-24 17:55
 * @Description: cn.kgm.makeGodV2.ruleEngine.ComplexEventExample
 */
public class ComplexEventExample {
    public static void main(String[] args) {
        // 初始化规则引擎
        RuleEngine ruleEngine = RuleEngine.getInstance();
        ruleEngine.registerRule(new RealmCheckRule());
        ruleEngine.registerRule(new SingleItemCheckRule());
        ruleEngine.registerRule(new AndConditionRule());
        ruleEngine.registerRule(new OrConditionRule());

        // 创建玩家数据
        Map<String, Integer> playerItems = new HashMap<>();
        playerItems.put("避毒丹", 2);  // 刚好有2个
        playerItems.put("飞行符", 0);  // 没有飞行符
        playerItems.put("灵石", 100);

        // 配置复杂条件：具备避毒丹2个 或者 飞行符1个
        ConditionConfig complexCondition = ConditionConfig.or(
                // 条件1：拥有避毒丹2个
                ConditionConfig.atomic("SINGLE_ITEM_CHECK",
                        Collections.singletonMap("避毒丹", 2)),
                // 条件2：拥有飞行符1个
                ConditionConfig.atomic("SINGLE_ITEM_CHECK",
                        Collections.singletonMap("飞行符", 1))
        );

        // 设置规则上下文
        RuleContext context = new RuleContext();
        context.setParam("playerRealm", "筑基期");
        context.setParam("playerItems", playerItems);
        context.setParam("subConditions", complexCondition.getConditions());

        // 执行OR条件
        RuleResult<Boolean> result = ruleEngine.executeRule("OR", context);

        System.out.println("=== 复杂条件检查结果 ===");
        System.out.println("条件描述: 具备避毒丹2个 或者 飞行符1个");
        System.out.println("玩家物品: " + playerItems);
        System.out.println("执行结果: " + result.getMessage());
        System.out.println("是否满足: " + result.getData());
        System.out.println("成功触发: " + (result.getData() ? "是" : "否"));
    }
}
